<?
include_once "gblinclude.lib";
include_once "listlayout.lib";
include_once "objinfo.lib";

$layoutFactory = new CLayoutFactory();
$header = $layoutFactory->getHeader();
echo $header;

$objName = $_GET["obj_name"];
$selectType = $_GET["select_type"];

$objInfo = CObjInfo::GetInstance();
$descFilePath = $objInfo->objInfos[$objName]->objDescFilePath;
$descClassName = $objInfo->objInfos[$objName]->objDescClass;
include_once "..".$descFilePath;

$objDesc = new $descClassName();

$cond=urldecode($_GET["cond"]);

$posFlag1 = strpos($cond, "=");
if ($posFlag1 !== FALSE)
{
	$tmpCnd = explode("=", $cond);
	$condArr = array();
	if (is_array($tmpCnd) && $cond !== 'undefined')
		$condArr[] = $objDesc->attrs[$tmpCnd[0]]->columnName.' IN ('.$tmpCnd[1].')';
}
$posFlag2 = strpos($cond, "cond_str");
if ($posFlag2 !== FALSE)
{
	$tmpCnd = explode(":", $cond);
	$condArr = array();
	if (is_array($tmpCnd) && $cond !== 'undefined')
		$condArr[] = $tmpCnd[1];
}

if ($_POST["submit_select"])
{
	echo '<script>';
	if ($_POST["select_type"] == 1)
	{
		$titleColumn = $objDesc->attrs[$objDesc->titleAttrName]->columnName;
		$persistFactory = CPersistFactory::getInstance();
		$dataObj = $persistFactory->getDataObject($_POST["obj_id"], $objDesc, $titleColumn);
		echo '
			window.opener.'.$_GET['cb'].'("'.RegisterID($_POST["obj_id"]).'", "'.$dataObj->$titleColumn.'");';
	}
	else
	{
		$getIds = $_GET["select_ids"];
		$ids = implode(";", $_POST["obj_id"]);	
		echo '
			window.opener.'.$_GET['cb'].'("'.$getIds.$ids.'");';
	}
	echo '
			window.opener.focus();
			window.close();
		</script>';
	exit;
}

$listLayout = new CListLayout($objDesc, getenv("DOCUMENT_ROOT").$objInfo->objInfos[$objName]->listLayoutDescXML, $condArr, true);

if ($selectType == 1)
	$listLayout->singleSelectFlag = true;
elseif($selectType == 2)
	$listLayout->mutiSelectFlag = true;
	
$tail = $layoutFactory->getTail();
$body = $listLayout->layout();

$js = '';

echo $js.$body.$tail;

?>
